﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Operations;
using NPOI.Util;
using SmartPlant.Model;
using SmartPlant.Model.Biz;
using SmartPlant.Services.Interfaces;
using SmartPlant.WinCore;
using static System.Formats.Asn1.AsnWriter;

namespace SmartPlant.Services
{
    public class DialogUIService : BaseService, IDialogUIService
    {
        public async Task<List<List<ViewQueryItemAttr>>> GetDialogUiAsync(decimal proId, int dialogPurpose, string objType)
        {
            if (!dialogUIRes.TryGetValue(objType, out var data))
            {
                // 第一次请求或缓存中不存在该key，从Web API获取数据    
                string uri = $"/api/Project/{proId}/dialog-ui/common-property-info/{dialogPurpose}/{objType}";
                var res = await PostAsync<List<List<ViewQueryItemAttr>>>(uri);
                dialogUIRes[objType] = res.data;// 将数据添加到缓存中  
                return res.data;
            }
            else
            {
                return dialogUIRes[objType];
            }
        }

        /// <summary>
        /// 缓存
        /// </summary>
        private static readonly Dictionary<string, List<List<ViewQueryItemAttr>>> dialogUIRes = new Dictionary<string, List<List<ViewQueryItemAttr>>>();
    }


}
